library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ stringr 1.4.0
## ✓ tidyr 1.1.4 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(gganimate)
whr <- read_csv("world-happiness-report.csv")
## Rows: 1949 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Country name
## dbl (10): year, Life Ladder, Log GDP per capita, Social support, Healthy lif...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
countries_plot <- whr %>%
clean_names() %>%
filter(country_name %in% c("Colombia", "Philippines", "China")) %>%
group_by(country_name) %>%
summarise(average_gdp = mean(log_gdp_per_capita)) %>%
ggplot(aes(x = country_name,
y = average_gdp,
fill = country_name)) +
geom_col() +
labs(title = "2016-2020 Average GDP per Capita in Adeline, Marcela, and Pia's Countries",
x = "",
y = "") +
theme_minimal() +
theme(legend.position = "none")
ggplotly(countries_plot)